<template>
  <el-card class="enterprise-info-card">
    <h2>企业信息管理</h2>
    <el-descriptions v-if="info" :column="1" border style="min-width: 700px; width: 100%;">
      <el-descriptions-item label="企业名称">{{ info.enterpriseName }}</el-descriptions-item>
      <el-descriptions-item label="所属行业">{{ info.industry }}</el-descriptions-item>
      <el-descriptions-item label="企业规模">{{ info.scale }}</el-descriptions-item>
      <el-descriptions-item label="企业地址">{{ info.address }}</el-descriptions-item>
      <el-descriptions-item label="联系方式">{{ info.contact }}</el-descriptions-item>
    </el-descriptions>
    <el-button type="primary" class="mt-2" @click="showEdit = true">编辑信息</el-button>
    <el-dialog v-model="showEdit" title="编辑企业信息" width="600px">
      <el-form :model="editForm" label-width="110px" ref="formRef">
        <el-form-item label="企业ID">
          <el-input v-model="editForm.id" disabled placeholder="企业ID不可修改" />
        </el-form-item>
        <el-form-item label="企业名称">
          <el-input v-model="editForm.enterpriseName" disabled placeholder="企业名称不可修改" />
        </el-form-item>
        <el-form-item label="所属行业">
          <el-input v-model="editForm.industry" />
        </el-form-item>
        <el-form-item label="企业规模">
          <el-input v-model="editForm.scale" />
        </el-form-item>
        <el-form-item label="企业地址">
          <el-input v-model="editForm.address" />
        </el-form-item>
        <el-form-item label="联系方式">
          <el-input v-model="editForm.contact" />
        </el-form-item>
      </el-form>
      <template #footer>
        <el-button @click="showEdit = false">取消</el-button>
        <el-button type="primary" @click="onSave" :loading="loading">保存</el-button>
      </template>
    </el-dialog>
  </el-card>
</template>

<script setup>
import { ref, onMounted } from 'vue'
import { ElMessage } from 'element-plus'
import { getEnterpriseInfo, updateEnterpriseInfo } from '@/api/enterprise'

const info = ref(null)
const showEdit = ref(false)
const editForm = ref({})
const loading = ref(false)
const formRef = ref()

const fetchInfo = async () => {
  try {
    const res = await getEnterpriseInfo()
    info.value = res.enterpriseInfo || res
    editForm.value = { ...res.enterpriseInfo } || {}
  } catch (e) {}
}
const onSave = async () => {
  loading.value = true
  try {
    // 只提交可编辑字段
    const { id, industry, scale, address, contact } = editForm.value
    await updateEnterpriseInfo({ id, industry, scale, address, contact })
    ElMessage.success('企业信息更新成功')
    showEdit.value = false
    fetchInfo()
  } catch (e) {}
  loading.value = false
}
onMounted(() => {
  fetchInfo()
})
</script>

<style scoped>
.enterprise-info-card {
  max-width: 900px;
  margin: 40px auto;
  padding: 30px 20px;
}
</style> 